import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {ApiProvider} from "../../providers/api/api";

/**
 * Generated class for the CourseDetailPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-course-detail',
  templateUrl: 'course-detail.html',
})
export class CourseDetailPage {
  courseId;
  courseName;
  unitCount;
  describe;
  constructor(public navCtrl: NavController, public navParams: NavParams,public http: ApiProvider) {
  }

  ionViewDidLoad() {
    this.courseId=this.navParams.get("course_id");
    this.courseInfo();
  }

  ionViewDidEnter()
  {
    this.courseId=this.navParams.get("course_id");
    this.courseInfo();
  }

  courseInfo()
  {
    this.http.post("/course/getCourseDetails.do",{courseId:this.courseId}).subscribe(item=>{
      if(item["Code"]=="11111111")
      {
        this.http.showToast(item["Message"],"bottom");
      }
      else{
        this.courseName=item["courseInfo"]["course_name"];
        this.unitCount=item["courseInfo"]["unit_num"];
        this.describe=item["courseInfo"]["course_complain"];
      }
    })
  }
}
